//登录
app.controller("i3618Ctrl", function ($scope, $state, $http, $ionicLoading) {
    var wx_code = localStorage.getItem("sessionId");
    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    //进入页面初始化
    angular.element(document).ready(function () {
        //验证是否绑定过帐号
        $scope.checkLogin(wx_code);
    });
    $scope.checkLogin = function (wx_code) {
        var _url = "http://sy.i3618.com.cn:8080"+getPath.name+"/app/a/loginByBanxing";
        $http({
            url: _url,
            method: "POST",
            headers:{'Content-Type':'application/x-www-form-urlencoded'},
            data: {sessionId:wx_code}
        }).success(function (data) {
                if (data.resultCode == 200) {
                    //登录成功，用户信息存到缓存中
                    $ionicLoading.hide();
                    var UserInfo = data.resultBean;
                    user_info = UserInfo;
                    //存放到缓存里
                    localStorage.setItem("UserInfo",JSON.stringify(UserInfo));
                    $state.go('home.today');
                } else {
                    $ionicLoading.show({
                        template: "微信登录失败",
                        duration: 3000
                    });
                }
            })
            .error(function () {
                $ionicLoading.hide();
                $ionicLoading.show({
                    template: "登录失败",
                    duration: 3000
                });
            });
    }
});
